<?php
/**
 * Created by PhpStorm.
 * User: Hongjw
 * Date: 2018/3/17
 * Time: 17:17
 */

namespace App\Tools\Common;


trait ClassInfo
{
    private static $classInfoM = null;
    private static $constArr = [];

    /**
     * 获取类信息
     * @return null|\ReflectionClass
     */
    public static function getClassAllInfo(){
        if(!self::$classInfoM){
            self::$classInfoM = new \ReflectionClass(self::class);
        }
        return self::$classInfoM;
    }

    /**
     * 获取常量
     * @param string $prefix
     * @return array
     */
    public static function getConst($prefix = 'AllConst'){
        if(isset(self::$constArr[$prefix])){
            return self::$constArr[$prefix];
        }
        $constants = self::getClassAllInfo()->getConstants();
        if($prefix != 'AllConst'){
            foreach ($constants as $key => $item){
                if(mb_strpos($prefix,$key) !== 0){
                    unset($constants[$key]);
                }
            }
        }
        return self::$constArr[$prefix] = $constants;
    }

    /**
     *
     */
    public function getConstByPrefix(){

    }


}